package com.fcscs.cservice.dao.hibernate;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.fcscs.core.dao.ConnectionManager;
import com.fcscs.core.domain.BaseEntity.DBLoc;
import com.fcscs.cservice.dao.CuisineTypeDao;
import com.fcscs.cservice.domain.CuisineType;

@SuppressWarnings("unchecked")
@Repository("cuisineTypeDao")
public class CuisineTypeDaoHibernate extends BaseDaoHibernate<CuisineType> implements CuisineTypeDao {

	private static DBLoc DBLoc = new CuisineType().getDBLoc();

	@Autowired
	private ConnectionManager connMgr;

	private static final String FIND = "from CuisineType where orgId = :orgId and propertyId = :propId and active = true";

	@Override
	protected Class<CuisineType> getCls() {
		return CuisineType.class;
	}

	@Override
	protected ConnectionManager getConnectionManager() {
		return connMgr;
	}

	@Override
	protected DBLoc getDBLoc() {
		return DBLoc;
	}

	@Override
	public <E extends CuisineType> E get(Class<E> cls, long id) {
		return (E) getConnectionManager().getCurrentSession(getDBLoc()).load(cls, id);
	}

	@Override
	public List<CuisineType> getCuisineTypes(long orgId, Long propId) {
		Query q = connMgr.getCurrentSession(getDBLoc()).createQuery(FIND);
		q.setLong("orgId", orgId);
		q.setParameter("propId", propId, Hibernate.LONG);
		return q.list();
	}

}
